next
Round
Technologies
Saved
Contribute
Login
next
Round
Technologies
Saved
Contribute
Login
Question Loading...
Iterator and Generator
1. What built-in JavaScript data structures are iterable by default? How does for...of work under the hood with them?
Level: Expert | Frequency: High
2. How would you use a generator to implement redux-saga-style side effect management? What makes generators a good fit for this?
Level: Expert | Frequency: High
3. What are Iterator Helpers (.map(), .filter(), .take(), .drop() on iterators natively)? What stage are they at in the TC39 proposal pipeline?
Level: Expert | Frequency: High
4. Are generators lazy? How do they differ from eager evaluation with arrays in terms of memory and performance?
Level: Expert | Frequency: High
5. What are the pitfalls of using for await...of with an async generator that makes network calls? How do you handle errors and cancellation?
Level: Expert | Frequency: High
6. Implement a take(n) utility that takes the first n values from any iterable — including infinite ones:
Level: Expert | Frequency: High
7. What is the difference between yield and return inside a generator?
Level: Expert | Frequency: High
8. When would you choose a generator over returning an array? What are the memory trade-offs?
Level: Expert | Frequency: High
9. What are the debugging challenges with generators (e.g., in stack traces and async flows)? How do you mitigate them?
Level: Expert | Frequency: High
10. What are the limitations of generators? What problems are they not a good fit for?
Level: Expert | Frequency: High
11. How does Array.from() use the iterator protocol? What's the difference between passing an iterable vs an array-like object?
Level: Expert | Frequency: High
12. How would you implement an infinite iterator (e.g., an infinite counter)? How do you safely consume it?
Level: Expert | Frequency: High
13. Can you pass a value into a generator using .next(value)? How does that work and what is the practical use case?
Level: Expert | Frequency: High
14. How would you implement a reusable iterable (one that can be iterated multiple times)?
Level: Expert | Frequency: High
15. Implement an async generator that fetches paginated API data, yielding one page at a time:
Level: Expert | Frequency: High
16. How would you implement a readable stream as an async iterable in Node.js?
Level: Expert | Frequency: High
17. How do Map, Set, Array, and String expose their iterators? Are they the same object or different?
Level: Expert | Frequency: High
18. What is the difference between a regular iterator and an async iterator? What protocol does an async iterator follow?
Level: Expert | Frequency: High
19. What happens if you forget to return { done: true } in a custom iterator? What are the consequences?
Level: Expert | Frequency: High
20. How do generators compose? Implement a pipeline of generator-based transformations (like RxJS operators but synchronous).
Level: Expert | Frequency: High
21. What is the difference between map.keys(), map.values(), and map.entries()? What do they return?
Level: Expert | Frequency: High
22. How do generators handle errors? How does .throw() interact with try/catch inside a generator?
Level: Expert | Frequency: High
23. In a data pipeline processing millions of records, how would you use generators to avoid loading everything into memory?
Level: Expert | Frequency: High
24. What happens to a try/finally block inside a generator when .return() is called externally?
Level: Expert | Frequency: High
25. How does destructuring and spread (...) use the iterator protocol internally?
Level: Expert | Frequency: High
26. Explain generator.return(value) and generator.throw(error). When would you use each in production?
Level: Expert | Frequency: High
27. How can generators be used to implement coroutines or cooperative multitasking in JavaScript?
Level: Expert | Frequency: High
28. How would you implement Promise-based async/await using generators and a runner function? (This is essentially how Babel transpiled async/await early on.)
Level: Expert | Frequency: High
29. How would you use a generator to implement a tree traversal (DFS) without recursion stack concerns?
Level: Expert | Frequency: High
30. What is the difference between an iterable and an iterator? Can something be both?
Level: Expert | Frequency: High
31. Explain what yield does. What does calling .next() return before and after a yield?
Level: Expert | Frequency: High
32. What does yield* do? How is it different from a regular yield?
Level: Expert | Frequency: High
33. What does Symbol.asyncIterator do? How does for await...of use it?
Level: Expert | Frequency: High
34. What does Symbol.iterator do? How would you make a plain object iterable from scratch?
Level: Expert | Frequency: High
35. Can you chain or compose custom iterators? Implement a map and filter for a custom iterator without converting to an array.
Level: Expert | Frequency: High
36. What is a generator function? How is it different from a regular function in terms of execution flow?
Level: Expert | Frequency: High
37. What is the Iterator Protocol in JavaScript? What two things must an object implement to be a valid iterator?
Level: Expert | Frequency: High
38. What is a 'lazy' iterator and why is it important for performance? Give a practical example.
Level: Expert | Frequency: High
All Topics
Basics
Engine
JIT
V8
Event Loop and Runtime
Concurrency and Threading
Bytecode and Parsing
Execution Context
Data Types
Functions
String Operations
Array Operations
this
Call Apply Bind
Closure
Objects
ES6 Classes
Events
ES6
Promises
Iterator and Generator
Error Handling
Web Workers
PWA
Web Sockets
Web Assembly
Garbage Collector
Modules
Browser APIS
Functional Programming
Currying
Higher Order Functions
Memoisation
Security
Code